package com.ruoyi.api.v1;

import com.github.pagehelper.PageHelper;
import com.ruoyi.cinema.BO.PageBo;
import com.ruoyi.cinema.BO.SubRequestBO;
import com.ruoyi.cinema.BO.SubTicketBO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.order.mapper.TicketOrderTicketInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("v1_subTicket")
@RequestMapping(value = "api/v1/subTicket")
public class SubTicketController  extends BaseController {

    @Autowired
    private TicketOrderTicketInfoMapper ticketOrderTicketInfoMapper;

    @RequestMapping(value = "getUnSubSell")
    public AjaxResult getUnSubSell() {
        List<SubTicketBO> list= ticketOrderTicketInfoMapper.selectUnSubSellTicket();
        return AjaxResult.success(list);
    }


    @RequestMapping(value = "getUnSubRefund")
    public AjaxResult getUnSubRefund() {
        List<SubTicketBO> list= ticketOrderTicketInfoMapper.selectUnSubRefundTicket();
        return AjaxResult.success(list);
    }

    @RequestMapping(value = "updateSubRefundStatus")
    public AjaxResult updateSubRefundStatus(@RequestBody List<String> ids) {
        if(null == ids || ids.isEmpty()){
          return AjaxResult.error(-1,"列表不能为空");
        }
        ticketOrderTicketInfoMapper.updateSubRefund(ids);

        return AjaxResult.success("更新成功");
    }


    @RequestMapping(value = "updateSubSellStatus")
    public AjaxResult updateSubSellStatus(@RequestBody List<String> ids) {
        if(null == ids || ids.isEmpty()){
            return AjaxResult.error(-1,"列表不能为空");
        }
        ticketOrderTicketInfoMapper.updateSubSell(ids);

        return AjaxResult.success("更新成功");
    }

    @RequestMapping(value = "selectSubmit")
    public AjaxResult selectSubmit(@RequestBody SubRequestBO subRequestBO) {
        PageBo<SubTicketBO> pageBo = new PageBo<>();
        if(null != subRequestBO && null != subRequestBO.getPage()){
            PageHelper.startPage(subRequestBO.getPage().getPageNo(),subRequestBO.getPage().getPageSize());
            pageBo.setPageNo(subRequestBO.getPage().getPageNo());
            pageBo.setPageSize(subRequestBO.getPage().getPageSize());
        }
        List<SubTicketBO> list= ticketOrderTicketInfoMapper.selectTicket(subRequestBO);
        pageBo.setList(list);
        return AjaxResult.success(pageBo);
    }

}
